<style>

</style>
<template>
    <div>

            <Spin size="large" fix v-if="spinShow"></Spin>
     
         <!-- 根据条件查询 -->
    <div>
      <el-form :inline="true"  class="demo-form-inline" ref="ruleForm">
        <el-form-item label="单据编号">
          <el-input v-model="documentNumber" placeholder="请输入单据编号查询"></el-input>
        </el-form-item>
        <el-form-item label="商品信息">
          <el-input v-model="productName" placeholder="请输入商品信息查询"></el-input>
        </el-form-item>
        <el-form-item label=" 单据日期 ">
          <el-date-picker
            v-model="begintime"
            type="datetimerange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :default-time="['12:00:00']"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <!-- <el-button type="primary" @click="findByPage">查询</el-button> -->
             <el-button type="primary" plain   @click="findByPage">查询</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </div>



      <!-- table展示 -->
      
    <!-- table展示 -->
    <div>
      <div style="margin-top: 20px;">
    
        <el-dropdown split-button type="primary" style="padding-left:20px" v-show="this.xlk">
          批量操作
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>
              <Icon type="ivu-icon ivu-icon-ios-checkmark-circle-outline"/>
              <span>审核</span>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>

      <br>
      <Table
        border
        
        :columns="columns4"
        :data="data1"
     
      >
        <template slot-scope="{ row, index }" slot="action">
            <el-button type="primary" plain   @click="findSalesOrderByDCNum(row)">查看</el-button>
        </template>

       

        <template slot-scope="scope" slot="status">
          <el-tag :type="scope.row.erpState.stateName==='审核'? 'primary':'danger'" >
            {{scope.row.erpState.stateName=='审核'?"审核":"未审核"}}
            </el-tag>
        </template>
      </Table>
    </div>
    <br>

    <!-- 分页 -->
    <div style="float:right">
      <Page
        :total="dataCount"
        :page-size="pageSize"
        @on-change="changepage"
        @on-page-size-change="_nowPageSize"
        show-elevator
      />
    </div>


     <!-- 根据订单编号查看 -->
    <Modal v-model="findSalseDMNumContent" title="详情" width="1340">
      <Table border ref="selection" :columns="columns5" :data="DMNumList" height="350" >
        <template slot-scope="{ row, index }" slot="resName">{{row.erpWarehouseinformation.resName}}</template>

       
          <template slot-scope="{ row, index }" slot="del">
            <!-- <Button type="info" size="large" @click="pretuihuo(row)">退货</Button> -->

             <el-button type="danger" round @click="pretuihuo(row)">退货</el-button>
         </template>

      
      </Table>
    </Modal>




    
    <!-- 退货的弹出框 -->
     <Modal
        width="1000"
        v-model="tuihuo"
        title="修改"
        @on-ok="tuihuo2"
        >

       <el-form :inline="true" :model="SalesOrderContent2" class="demo-form-inline">
         <el-form-item label="单据编号:">
              <el-input v-model="SalesOrderContent2.documentNumber"  disabled=""></el-input>
            </el-form-item> 

                        
               <el-form-item label="仓库:">
              <el-input v-model="SalesOrderContent2.resName"  disabled=""></el-input>
            </el-form-item> 

            <el-form-item label="id:">
                    <el-input v-model="SalesOrderContent2.id" disabled=""></el-input>
            </el-form-item>

              
         <br>

          <el-form-item label="商品名称:">
                    <el-input v-model="SalesOrderContent2.productName" disabled=""></el-input>
            </el-form-item>
         

             <el-form-item label="数量:">
              <el-input v-model="SalesOrderContent2.number"  ></el-input>
            </el-form-item> 

            <el-form-item label="单价:">
              <el-input v-model="SalesOrderContent2.unitPrice"  disabled=""></el-input>
            </el-form-item>   
       </el-form>



    </Modal>




    </div>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {

      tuihuo:false,

      //根据单据编号查询的model框
      findSalseDMNumContent:false,

      // 根据单据编号查询
      DMNumList:[],

      xlk:false,
      tableSelection:[],
       columns5: [
        {
            title:"#",
            key:"id",
            align:"center",
        },
         {
          title: "单据编号",
          key: "documentNumber",
            align:"center",
        },
        {
          title:"序列号",
          key:"productNumber",
            align:"center",
        },
        {
          title: "商品名称",
          key: "productName",
            align:"center",
        },
      
       
        {
          title:"数量",
          key:"number",
            align:"center",
        },
        {
          title:"单价",
          key:"unitPrice",
            align:"center",
        },
         {
          title:"总价",
          key:"countPrice",
            align:"center",
        },
         {
          title: "仓库",
          slot: "resName",
            align:"center",
        },
        {
          title:"扩展信息",
          key:"remark",
            align:"center",
        },
       
         {
          title:"退货",
          slot:"del",
            align:"center",
        }
       
      ],
        columns4: [
      
        {
          title: "#",
          key: "id",
            align:"center",
        },
        {
          title: "客户名称",
          key: "clientName",
            align:"center",
        },
        {
          title: "单据编号",
          key: "documentNumber",
            align:"center",
        },
        {
          title: "商品信息",
          key: "productName",
            align:"center",
        },
        {
          title: "单据日期",
          key: "documentDate",
            align:"center",
        },
        {
          title: "操作员",
          key: "operator",
            align:"center",
        },
        {
          title: "金额合计",
          key: "totalAmount",
            align:"center",
        },
        {
          title: "状态",
          slot: "status",
            align:"center",
        },
       
        {
          title: "用户操作",
          slot: "action",
            align:"center",
        }
        
      ],
      data1: [],
     

         // 分页的条件
      productName: "",
      documentNumber: "",
      begintime: [],


      //分页
        pageSize: 5, //每页显示多少条
      dataCount: 0, //总条数
      pageCurrent: 1, //当前页,


    //特效
    spinShow:true,

    SalesOrderContent2:{

    }

    };
  },

  created(){
    this.getSalesOrderList();
  },
  methods: {


    //查看
    findByPage(){
        axios
        .post(
          "//localhost:8082/salesOrder/getPageBySalesOrder2?documentNumber=" +
            this.documentNumber +
            "&productName=" +
            this.productName +
            "&time=" +
            this.begintime +
            "&pageSize=" +
            this.pageSize +
            "&pageCurrent=" +
            this.pageCurrent
        )
        .then(res => {
          console.log("13123123123213")
          console.log(res.data);
          this.dataCount = res.data.countTotal;
          this.data1 = res.data.list;
         
          //当从数据库获取完毕  关闭加载特效
          this.spinShow=false;
          // this.begintime = "";
        });
    },

         // 查找所以销售订单的信息   // 分页
    getSalesOrderList() {
      axios
        .post(
          "//localhost:8082/salesOrder/getPageBySalesOrder2?documentNumber=" +
            this.documentNumber +
            "&productName=" +
            this.productName +
            "&time=" +
            this.begintime +
            "&pageSize=" +
            this.pageSize +
            "&pageCurrent=" +
            this.pageCurrent
        )
        .then(res => {
          console.log("13123123123213")
          console.log(res.data);
          this.dataCount = res.data.countTotal;
          this.data1 = res.data.list;
         
          //当从数据库获取完毕  关闭加载特效
          this.spinShow=false;
          // this.begintime = "";
        });
    },



      //点击这个,即可换页数
    changepage(index) {
      axios
        .get(
          "http://localhost:8082/salesOrder/getPageBySalesOrder2?documentNumber=" +
            this.documentNumber +
            "&productName=" +
            this.productName +
            "&time=" +
            this.begintime +
            "&pageSize=" +
            this.pageSize +
            "&pageCurrent=" +
            index
        )
        .then(response => {
          this.dataCount = response.data.countTotal;
          this.data1 = response.data.list;
        });
    },

    //每页显示的数据条数
    _nowPageSize(index) {
      //实时获取当前需要显示的条数
      this.pageSize = index;
    },



     // 重置
    resetForm() {
      this.documentNumber = "";
      this.begintime = [];
      this.productName = "";
    },

     // 根据单据编号查询
    findSalesOrderByDCNum(row) {
      axios
        .get(
          "http://localhost:8082/salesOrderContent/getSalesOrderByDCNum?documentNumber=" +
            row.documentNumber
        )
        .then(res => {
          this.DMNumList = res.data;
          console.log(this.DMNumList)
          this.findSalseDMNumContent = true;
        });
    },

    

    //预退货
    pretuihuo(row){
      this.SalesOrderContent2=row;
      this.SalesOrderContent2.resName=row.erpWarehouseinformation.resName;
      console.log(this.SalesOrderContent2);
      this.findSalseDMNumContent=false;
      this.tuihuo=true;

    },

    //退货
    tuihuo2(){
       axios.post("http://localhost:8082/salesOrder/ReturnSalesOrderContent",this.SalesOrderContent2).then(res=>{
          console.log(res.data)
          if(res.data==1){
          this.$notify({
          title: '成功',
          message: '退货成功!',
          type: 'success'
        });
          }else if(res.data==2){
             this.$notify({
          title: '警告',
          message: '您没有修改销售数量!',
          type: 'warning'
        });
          }else if(res.data==3){
             this.$notify({
          title: '警告',
          message: '退货数量为负数!',
          type: 'warning'
        });
          }else{
             this.$notify({
          title: '警告',
          message: '退货失败!',
          type: 'warning'
        });
          }
        
       })
    }
 
  }
};
</script>
